package com.bestattempt.utility.bind;

import com.bestattempt.utility.bind.initializers.*;
import com.bestattempt.utility.bind.initializers.defaultImpl.ObjectInitializer;
import com.bestattempt.utility.bind.initializers.defaultImpl.MapInitializer;
import com.bestattempt.utility.bind.initializers.defaultImpl.ListInitializer;
import com.bestattempt.utility.bind.initializers.defaultImpl.ArrayInitializer;

import java.util.Map;
import java.util.List;
import java.util.HashMap;
import java.lang.reflect.Array;

/**
 * TODO: Document me
 *
 * @author Ganeshji Marwaha
 * @since Oct 14, 2006
 */
public class Initializers {
    private static Map<Class, Initializer> initializers = new HashMap<Class, Initializer>();

    static {
        initializers.put(List.class,    new ListInitializer());
        initializers.put(Map.class,     new MapInitializer());
        initializers.put(Array.class,   new ArrayInitializer());
        initializers.put(Object.class,  new ObjectInitializer());
    }

    public static Initializer get(Class type) {
        Initializer initializer = initializers.get(type);
        if(initializer == null) {
            initializer = initializers.get(Object.class);
        }
        return initializer;
    }

    public static void registerInitializer(Class type, Initializer initializer) {
        initializers.put(type, initializer);
    }
}
